import instance from '@/utils/axios.js'


//文章频道列表
function getChannelList() {
    return instance({
        url: '/v1_0/channels',
        method: 'get'
    })


}

//文章列表
function getArticleList({ channel_id, timestamp }) {
    return instance({
        url: '/v1_0/articles',
        method: 'get',
        params: {
            with_top: 1,
            channel_id,
            timestamp
        }
    })
}

//文章详情
function getArticleInfo(id) {
    return instance({
        url: `/v1_0/articles/${id}`,
        method: 'get'
    })
}
export { getChannelList, getArticleList, getArticleInfo }


//用户关注


function addFollowing(target) {
    return instance({
        url: `/v1_0/user/followings`,
        method: 'post',
        data: { target }
    })
}


function removeFollowing(target) {
    return instance({
        url: `/v1_0/user/followings/${target}`,
        method: 'delete',


    })
}


export { addFollowing, removeFollowing }
//用户点赞


function addLikings(target) {
    return instance({
        url: '/v1_0/article/likings',
        method: 'POST',
        data: { target }
    })
}

function removeLikings(target) {
    return instance({
        url: `/v1_0/article/likings/${target}`,
        method: "DELETE"
    })
}

export { addLikings, removeLikings }


//用户不喜欢


function addDisLike(target) {
    return instance({
        url: '/v1_0/article/dislikes',
        method: 'post',
        data: { target }
    })
}


function removeDisLike(target) {
    return instance({
        url: `/v1_0/article/dislikes/${target}`,
        method: 'delete'
    })
}

export { addDisLike, removeDisLike }

/* 8.搜索推荐词 */

const getSuggestion = keyword => {
  return instance({
    method: 'get',
    url: '/v1_0/suggestion',
    params: {
      q: keyword
    }
  })
}

//导出接口
export { getSuggestion }

/* 搜索结果列表 */
function getSearchList({page,q}){
    return instance({
        url: '/v1_0/search',
        method: 'get',
        params: {
            per_page:10,
            page,
            q
          }
    })
}
export { getSearchList }